package com.hxkj.controller.article;

import com.hxkj.domain.po.RankingManagement;
import com.hxkj.service.article.RankingManagementService;
import com.platform.common.dispatcher.util.ResultStructUtils;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;

/**
 * 模板解析控制层
 * <p>
 * Created by yaosy on 2018年6月19日09:23:15
 */
@RestController
@RequestMapping("/ranking")
public class RankingManagementController {


    @Autowired
    private RankingManagementService rankingManagementService;

    /**
     * 获取合作公司列表
     * @param parameterDataStruct
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    public Callable<ResultPageStruct<RankingManagement>> getList(@ModelAttribute ParameterDataStruct<RankingManagement> parameterDataStruct) throws Exception {
        return () -> ResultStructUtils.buildResultPageStruct(rankingManagementService.getlist(parameterDataStruct.getData() == null ?
                new RankingManagement() : parameterDataStruct.getData(), parameterDataStruct.getPageTo()), "param=value");
    }

    /**
     * 新建排行榜
     *
     * @param rankingManagement
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public void save(@ModelAttribute RankingManagement rankingManagement) throws Exception{
         rankingManagementService.save(rankingManagement);
    }

    /**
     * 批量删除排行榜
     *
     *
     * @param rankingManagement
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public  Callable<ResultMessageStruct>  remove(@ModelAttribute RankingManagement rankingManagement) {
        return ()-> rankingManagementService.delete(rankingManagement);
    }

    /**
     * 获取单条排行榜
     *
     * @param rankingManagement
     * @throws Exception
     */
    @RequestMapping(value = "/get",method = RequestMethod.POST)
    public  Callable<ResultDataStruct<RankingManagement>> get(@ModelAttribute RankingManagement rankingManagement) {
        return ()-> rankingManagementService.get(rankingManagement);
    }

    /**
     * 保存单条排行榜
     * @param rankingManagement
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/modify",method = RequestMethod.POST)
    public  Callable<ResultMessageStruct>  modify(@ModelAttribute RankingManagement rankingManagement)  throws Exception{
        return ()-> rankingManagementService.modify(rankingManagement);
    }

}
